package com.parfinex.part2;

import java.io.*;
import java.util.*;

public class InputContent {
    public static void main(String[] args) throws IOException {
        String inputScan = null;
        Scanner scanner = new Scanner(System.in);//从键盘接收数据
        System.out.println("请输入字符串，结束请输入end:");
        ArrayList<String> arrayList = new ArrayList();
        inputScan = scanner.next();
        while (!inputScan.equals("end"))
        {
            arrayList.add(inputScan);
            System.out.println("请输入字符串，结果输入，请输入end:");
            inputScan = scanner.next();
        }

        Collections.sort(arrayList);
        Collections.reverse(arrayList);
        String pathName = "abc.txt";
        BufferedWriter bw = new BufferedWriter(new FileWriter(pathName));
        for (String s:arrayList) {
            bw.write(s);
            bw.newLine();
            bw.flush();
        }

        //FileOutputStream fos = new FileOutputStream(pathName,true);
        //bjectOutputStream oos = new ObjectOutputStream(fos);
        //oos.writeObject(arrayList);
        //System.out.println(arrayList);
        //for (int x = 0; x < arrayList.size(); x++) {
        //    System.out.println(arrayList.get(x));
        //    String wr = arrayList.get(x);
            //oos.writeObject(arrayList);
        //    System.out.println("写入成功！");
        //}
        //oos.close();
        bw.close();
    }

}
